﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Model;
using Common;
using MySql.Data.MySqlClient;

namespace DAL
{
    public class SOP_ActivityInfoDAL
    {
 
        /// <summary>
        /// 邀请好友
        /// </summary>
        /// <param name="BossID"></param>
        /// <param name="CouponList"></param>
        /// <returns></returns>
        public int AddInvitefriendsByActivity(AMP_Invitefriends model)
        {
            using (MySqlConnection conn = DAL.SqlHelper.Settings.GetSOPMySqlConnection(true))
            {
                try
                {
                    MySqlCommand cmd = new MySqlCommand("P_AddInvitefriendsByActivity_MZ", conn);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("@ActivityCode_Para", MySqlDbType.VarChar, 64).Value = model.ActivityCodeObj;
                    cmd.Parameters.Add("@CustomerID_Para", MySqlDbType.Int32).Value = model.CustomerID;
                    cmd.Parameters.Add("@FriendCustomerID_Para", MySqlDbType.Int32).Value = model.FriendCustomerID;
                    cmd.Parameters.Add("@FriendMobile_Para", MySqlDbType.VarChar,11).Value = model.FriendMobile;
                    cmd.Parameters.Add("@IPAddress_Para", MySqlDbType.VarChar, 20).Value = model.IPAddress;
                    cmd.Parameters.Add("@Remart_Para", MySqlDbType.VarChar,200).Value = model.Remart;
                    cmd.Parameters.Add("@AddTime_para", MySqlDbType.DateTime).Value = model.AddTime;
                    cmd.Parameters.Add("@IsSuccess_Para", MySqlDbType.Int32).Value = 0;
                    cmd.Parameters["@IsSuccess_Para"].Direction = ParameterDirection.Output;

                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }
                    cmd.ExecuteNonQuery();

                    Object ObjRtID = cmd.Parameters["@IsSuccess_Para"].Value;
                    int ActivityID = ObjRtID == null || ObjRtID.ToString() == string.Empty ? -5 : (int)ObjRtID;
                    return ActivityID;
                }
                catch (Exception ex)
                {
                    return -1000;
                }
                finally
                {
                    conn.Close();
                }
            }


        }
    }
}
